package com.linkhub.oms.admin.modules.stock.domain.dto;

import cn.hutool.core.collection.CollUtil;
import com.google.common.collect.Lists;
import com.linkhub.oms.admin.modules.wms.domain.dto.TransferOrderNoticeDTO;
import com.linkhub.oms.common.util.WmsUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;
import java.util.Objects;

/**
 * @ClassName StockTransferDTO
 * @Description TODO
 * @Author XieYu
 * @Date 2024/7/13 22:41
 * @Version 1.0
 */
@Data
public class StockTransferDTO {

    @ApiModelProperty(value = "用户id")
    private String userId;

    @ApiModelProperty(value = "仓库")
    private String stashName;

    @ApiModelProperty(value = "入库单号")
    private String businessNo;

    @ApiModelProperty(value = "本地商品skuId")
    private String skuId;

    @ApiModelProperty(value = "数量")
    private Integer skuQuantity;

    private String sourceType;
    private String targetType;

    public static List<StockTransferDTO> convert(TransferOrderNoticeDTO transferOrderNoticeDTO) {
        List<StockTransferDTO> results = Lists.newArrayList();
        if (Objects.nonNull(transferOrderNoticeDTO) && CollUtil.isNotEmpty(transferOrderNoticeDTO.getOrderLines())) {
            for (TransferOrderNoticeDTO.OrderLine orderLine : transferOrderNoticeDTO.getOrderLines()) {
                StockTransferDTO stockTransferDTO = new StockTransferDTO();
                stockTransferDTO.setUserId(WmsUtil.getUserId(orderLine.getItemCode()));
                stockTransferDTO.setStashName(transferOrderNoticeDTO.getWarehouseCode());
                stockTransferDTO.setBusinessNo(transferOrderNoticeDTO.getAdjustmentOrderCode());
                stockTransferDTO.setSkuId(WmsUtil.getSkuId(orderLine.getItemCode()));
                stockTransferDTO.setSourceType(orderLine.getSource().getInventoryType());
                stockTransferDTO.setTargetType(orderLine.getTarget().getInventoryType());
                stockTransferDTO.setSkuQuantity(Integer.parseInt(orderLine.getActualQty()));

                results.add(stockTransferDTO);
            }
        }
        return results;
    }
}
